<?php
namespace app\passport\validate;
use \think\Validate;

/**
 * 通行证基础信息统一验证系统 20161019
 */

class passport extends Validate
{
    use \app\common\validate\Validate;

    protected $rule = [
        'email'     =>  'email|unique:passport',//unique 数据表唯一性验证
        'telphone'  =>  ['regex'=>'checkTelphone:','unique'=>'passport'],
        'repasswd'  =>  'require|confirm:passport',
        'ip'        =>  'ip',
        'username'  =>  'alphaDash|regex:[a-z].*',
        //'nickname'  =>  '',//用户名验证法则,需要定制一套用户名的规则
    ];

    protected $message = [
/*        'title.require' => '标题必须填写',
        'title.length'  => '标题长度必须在2-25个字符之宰',
        'url.require'   => '友情链接必须填写',
        'url.url'       => '友情链接必须是一个网址',
        'status.in'     => '状态值不正确',
        'sort.integer'  => '排序必须是一个整数',*/
    ];

    protected $scene = [
        'register'  => ['email', 'telphone', 'repasswd'],
        'login'     => ['email'=>'email','telphone'=>'checkTelphone:'],
    ];

    //自定义验证规则
    protected function checkEmail($value,$rule,$data)
    {

        return $rule == $value ? true : '名称错误';
    }

    protected function checkTelphone($value,$rule,$data)
    {
        return preg_match('/^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/ ',$value)?true:'不是手机号';
    }
}
